package com.huang.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huang.eduservice.entity.EduCourse;
import com.huang.eduservice.entity.EduTeacher;
import com.huang.eduservice.service.EduCourseService;
import com.huang.eduservice.service.EduTeacherService;
import com.hunag.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherFront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    @GetMapping("pageTeacher/{page}/{limit}")
    public R getPageTeacher(@PathVariable long page, @PathVariable long limit) {
        Page<EduTeacher> pageTeacher = new Page<>(page, limit);
        Map<String, Object> map = teacherService.getTeacherFrontList(pageTeacher);
        return R.ok().data(map);
    }

    //通过t id  获取讲师相关信息
    @GetMapping("getInfoByid/{id}")
    public R getInfoByid(@PathVariable String id) {
        EduTeacher eduTeacher = teacherService.getById(id);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", id);
        List<EduCourse> one = courseService.list(wrapper);
        return R.ok().data("eduTeacher", eduTeacher).data("courseInfo", one);
    }

}
